package com.trg.flex.frm.validation
{
	import mx.controls.Alert;
	import mx.events.ValidationResultEvent;
	import mx.utils.ObjectUtil;
	import mx.validators.ValidationResult;
	import mx.validators.Validator;

	public class NotNullValidator extends Validator
	{
		public function NotNullValidator()
		{
			super();
			required = false;
		}
		
		private var _required:Boolean;
		
		override public function validate(value:Object=null, suppressEvents:Boolean=false):ValidationResultEvent {
			//This whole required business is a roundabout hack to keep the
			//Validator from bailing out when the value is null. The value of
			//required is restored in doValidation.
			_required = required;
			required = true;
			return super.validate(value, suppressEvents);
		}
		
		override protected function doValidation(value:Object):Array
	    {
			required = _required; //restore required, see above.
			
			var results:Array;

			if (value == null) {
				results = [ new ValidationResult(true, "", "requiredField",
                                            requiredFieldError) ];
			} else {
				results = super.doValidation(value);
			}
			
			return results;
	    }
		
	}
}